<?php
class Admin_Form_Adsfor extends Zend_Form
{
    public function init()
    {
        $this->setName("admin");
        
        $id = new Zend_Form_Element_Hidden('id');
        $id->addFilter('Int');
        
        $title = new Zend_Form_Element_Text('title');
        $title->setLabel('Tiêu đề (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
        $title->setAttrib('size', 60);
        
        $createD = new Zend_Form_Element_Text('createDate');
        $createD->setLabel('Ngày Tạo (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
        $createD->setAttrib('size', 60)->setAttrib('class','datepicker2')->setAttrib('placeholder','dd/mm/yy');
        $startD = new Zend_Form_Element_Text('startDate');
        $startD->setLabel('Ngày Bắt Đầu (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
        $startD->setAttrib('size', 60)->setAttrib('class','datepicker2')->setAttrib('placeholder','dd/mm/yy');
        $endD = new Zend_Form_Element_Text('endDate');
        $endD->setLabel('Ngày Kết Thúc (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
        $endD->setAttrib('size', 60)->setAttrib('class','datepicker2')->setAttrib('placeholder','dd/mm/yy');                                        

        $con = new Zend_Form_Element_Text('content');
        $con->setLabel('Nội dung (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
        $con->setAttrib('size', 60);
                
        $user = new Zend_Form_Element_Multiselect('userId');
        $user->setLabel('Tài khoản sở hữu');
        $user->setAttrib('size', 5);  
        $modelU = new Admin_Model_User();
        $userL = $modelU->getAllData();
        foreach($userL as $u) $user->addMultiOption($u['userId'],$u['email']);
        
        $viewer = new Zend_Form_Element_Multiselect('viewer');
        $viewer->setLabel('Nhân Viên Duyệt Tin');
        $viewer->setAttrib('size', 5);  
        $modelA = new Admin_Model_Admin();
        $adminL = $modelA->getAllData();
        foreach($adminL as $a) $viewer->addMultiOption($a['adminId'],$a['username']);
                
        $tran = new Zend_Form_Element_Select('transaction');
        $tran->setLabel('Loại Giao Dịch (*)');        
        $tran->addMultiOption('-1','--- Chọn hình thức giao dịch ---');
        $tran->addMultiOption('sale','Bán');
        $tran->addMultiOption('rent','Cho Thuê');                                        
                                
        $estate = new Zend_Form_Element_Select('estate');
        $estate->setLabel('Loại Bất Động Sản (*)');                                                              
                                                  
        $area = new Zend_Form_Element_Text('area');
        $area->setLabel('Diện Tích (M2) (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
        $area->setAttrib('size', 60);
        
        $unit = new Zend_Form_Element_Select('unit');
        $unit->setLabel('Đơn vị');                        
        
        $total = new Zend_Form_Element_Text('total');
        $total->setLabel('Tổng Tiền')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
                    
        $cat = new Zend_Form_Element_Text('contact');
        $cat->setLabel('Người Liên Hệ (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
        $cat->setAttrib('style','width: 180px');
        
        $mobi = new Zend_Form_Element_Text('mobile');
        $mobi->setLabel('Số Điện Thoại Di Động (*)')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty');
        $mobi->setAttrib('style','width: 180px');
        
        $email = new Zend_Form_Element_Text('email');
        $email->setLabel('Email')->addFilter('StripTags')->addFilter('StringTrim')->addValidator('EmailAddress');        
        $email->setAttrib('style','width: 180px');
        
        $phone = new Zend_Form_Element_Text('phoneContact');
        $phone->setLabel('Số Điện Thoại Bàn')->addFilter('StripTags')->addFilter('StringTrim');
        $phone->setAttrib('style','width: 180px');
        
        $status = new Zend_Form_Element_Select('status');
        $status->setLabel('Tình trạng tin');        
        $status->addMultiOption('1','Hoạt Động');
        $status->addMultiOption('0','Tạm Khoá');                    
            
        $city = new Zend_Form_Element_Select('city');
        $city->setLabel('Tỉnh/Thành Phố (*)')->setAttrib('style','width: 180px');        
        $city->addMultiOption('-1','--- Tỉnh/Thành Phố ---');
        $modelProvince = new Admin_Model_Province();
        $provinceL = $modelProvince->getAllData();
        foreach($provinceL as $pro) $city->addMultiOption($pro['provinceid'],$pro['name']);           
            
        $dis = new Zend_Form_Element_Select('district');
        $dis->setLabel('Quận/Huyện (*)')->setAttrib('style','width: 180px');
        $war = new Zend_Form_Element_Select('ward');
        $war->setLabel('Phường/Xã')->setAttrib('style','width: 180px');                                    
        $proj= new Zend_Form_Element_Select('project');
        $proj->setLabel('Dự án')->setAttrib('style','width: 180px');        
        
        $add = new Zend_Form_Element_Text('address');
        $add->setLabel('Địa chỉ')->addFilter('StripTags')->addFilter('StringTrim');
        $add->setAttrib('style','width: 200%');            
                
        //////////////////////////////////////////////////                                                                                                          
        $modelOther = new Admin_Model_Other();
        $otherList = $modelOther->getAllData()->toArray();                                        
        foreach($otherList as $other){               
            if($other['groupInfo'] == 'otherInfo' && $other['elementType'] == 'text'){                
                $info = new Zend_Form_Element_Text($other['id']);
                $info->setLabel($other['name']);                
                $info->setAttrib('class','resourceIdAdmin')->setAttrib('style','width: 180px');
                $info->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper')->removeDecorator('Label');
                $this->addElement($info);                                  
            }                                                    
        }
        
        foreach($otherList as $other){
            if($other['groupInfo'] == 'otherUtility' && $other['elementType'] == 'check'){
                $info = new Zend_Form_Element_Checkbox($other['id']);
                $info->setLabel($other['name']);                
                $info->setAttrib('name','otherUtility[]')->setCheckedValue($other['id']);
                $info->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper')->removeDecorator('Label');
                $this->addElement($info);    
            }                                                    
        }                       
        
        // submit button
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setAttrib('id','submitbutton');
        $submit->setAttrib('class',"button medium");
        $submit->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper');
        
        $reset = new Zend_Form_Element_Reset('reset');
        $reset->setAttrib('id','submitbutton');
        $reset->setAttrib('class',"button medium");
        $reset->removeDecorator('HtmlTag')->removeDecorator('DtDdWrapper');                
                
        // add elements to form
        $this->addElements(array (
            $id, $title, $createD, $startD, $endD, $con, $user, $tran, $estate,
            $area, $unit, $price, $total, $cat, $mobi, $phone, $email, $status,
            $city, $dis, $war, $proj, $add, $viewer,        
            $submit, $reset
        ));                
    }
}

